﻿#include <osgViewer/Viewer>
#include <osg/GraphicsContext>
#include <osgDB/ReadFile>
#include <osgGA/GUIEventHandler>
#include <osgGA/GUIActionAdapter>
#include <osgViewer/config/SingleWindow>

#include <iostream>
#include "Common.h"


int main()
{
	osg::ref_ptr<osgViewer::Viewer> viewer = new osgViewer::Viewer;

	//osgViewer::Viewer::Windows ws;
	//viewer->getWindows(ws);	// run里创建的
	//if (ws.empty())
	//{
	//	std::cout << "window list is empty!" << std::endl;
	//}

	viewer->apply(new osgViewer::SingleWindow(100, 100, 800, 600, 0));
	viewer->addEventHandler(new ChangeWindow);
	viewer->setSceneData(osgDB::readNodeFile("glider.osg"));
	viewer->run();


	/*
	osg::GraphicsContext::WindowingSystemInterface* ws			// 封装了win32,linux,apple...的窗口系统接口
		= osg::GraphicsContext::getWindowingSystemInterface(); // ws依赖于osgViewer,它里面有个静态变量，getInterface返回的就是这个变量，所以程序连接了viewer库才会获取到ws。
															   // 静态变量有windows版的，linux版的，这个是cmake决定把哪个版本的源文件拿进来编译成库。
	unsigned int height, width;
	osg::GraphicsContext::Traits trais;
	if (ws)
	{
		std::cout << "Get device interface success" << std::endl;
		ws->getScreenResolution(trais, width, height);
		std::cout << "系统分辨率为：" << width << "x" << height << std::endl;
		std::cout << "边框：" << trais.windowDecoration << std::endl;
		trais.x = 100;
		trais.y = 100;
		trais.width = 800;
		trais.height = 600;
		ws->setScreenResolution(trais, 800, 600);
	}
	else
	{
		std::cout << "Get device interface failed" << std::endl;
	}
	*/

	/*
	* 可以设置环境变量OSG_WINDOW，则viewer的run函数里会调用setUpViewInWindow函数创建一个指定大小的窗口。
	* e.g. OSG_WINDOW = 50 50 800 600
	*/

	return 0;
}